package com.example.rabbitmq.topic.service;

import com.example.entity.Emp;
import com.example.service.EmpService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Auther:
 * @Description:
 * @Date: 2019/12/27 13:05
 */
@Component
@RabbitListener(queues = "topic.man")// 监听MQ中名称为 MyDirectQueue 的队列
public class TopicReciveManService {
    @Autowired
    private EmpService empService;

    @RabbitHandler
    public void process(String message) {
        try {
            message += "_topic.man";
            System.out.println("TopicReciveManService  客户端接收到的消息为：  " + message);
            Emp emp = empService.getEmpId("1");
            emp.setEmpName(message);
            empService.updateById(emp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
